package net.zbus.pubsub;

import net.zbus.Worker;
import net.zbus.WorkerConfig;
import net.zbus.ZMQ;
import net.zbus.ZMsg;
import net.zbus.ZMQ.Context;


public class Subscriber {
 
	public static void main(String[] args) {  
		Context ctx = ZMQ.context(1);
		
		WorkerConfig config = new WorkerConfig();
		config.setCtx(ctx);
		config.setHost("10.60.60.13"); 
		config.setService("APEX_PUB");
		config.setMode(WorkerConfig.MODE_PUBSUB);
		
		Worker worker = new Worker(config);
		 
		String topic = "*";
		worker.subscribe(topic);
		
		System.out.format("Subscriber on '%s', waiting for message...\n", topic);
		while(true){
			try{ 
				ZMsg msg = worker.recv();
				
				msg.dump();
			}catch (Exception e) {
				e.printStackTrace();
				break;
			}
		}
		 
		worker.destroy(); 
		ctx.term();
	}

}
